﻿using System;
using System.Collections.Generic;

namespace InternetSpiderLib
{
    /// <summary>
    /// 场景动作
    /// </summary>
    public interface ISceneAction
    {
        /// <summary>
        /// 运行场景动作
        /// </summary>
        /// <param name="data"></param>
        void Run(DataBox data);
    }

    /// <summary>
    /// 列表场景动作
    /// </summary>
    public class ListSceneAction : ISceneAction
    {
        protected List<ISceneAction> Actions = new List<ISceneAction>();

        public ListSceneAction(List<ISceneAction> actions)
        {
            Actions.AddRange(actions);
        }

        public void Run(DataBox data)
        {
            foreach (var item in Actions)
            {
                var temp = new DataBox(data);
                item.Run(temp);
            }
        }
    }

    /// <summary>
    /// 匿名的场景动作
    /// </summary>
    public class AnonymousSceneAction : ISceneAction
    {
        private Action<DataBox> Action { get; set; }

        public AnonymousSceneAction(Action<DataBox> action)
        {
            Action = action;
        }

        public void Run(DataBox data)
        {
            Action?.Invoke(data);
        }
    }
}